﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CacheService.Standard;
using Microsoft.AspNetCore.Mvc;
using MODEL.Model;
using SERVICE.Admin.IService;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Admin.Controllers.Components
{
    public class NavViewComponent : ViewComponent
    {
        ISyetemService syetemService;
        ICache cache;
        public NavViewComponent(ICache cache, ISyetemService syetemService) {
            this.cache = cache;
            this.syetemService = syetemService;
        }
        public async Task<IViewComponentResult> InvokeAsync()
        {
            var key = Request.Cookies["key"];
            var user = syetemService.GetLoginManger(key);
            ViewBag.user = user;
            var menus = cache.get<List<SystemMenu>>($"{key}_menus");
            ViewBag.menus = menus;
            var path = $"/{RouteData.Values["controller"]}/{RouteData.Values["action"]}";
            ViewData["path"] = path;
            return View();
        }
    }
}
